package com.app.mingluxing.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.app.mingluxing.R;
import com.app.mingluxing.bean.CarePeople;
import com.app.mingluxing.utils.Constant;

import java.util.List;

/**
 * Created by Aaron on 15/8/10.
 */
public class UserAdapter extends BaseAdapter {
    private List<CarePeople> list;
    private Context ctx;

    public UserAdapter(Context ctx, List<CarePeople> list) {
        this.ctx = ctx;
        this.list = list;
    }
    public void setData(List<CarePeople> list){
        this.list = list;
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;

        if (convertView == null) {

            convertView = View.inflate(ctx, R.layout.item_binder, null);
            viewHolder = new ViewHolder();
            viewHolder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            viewHolder.tv_tel = (TextView) convertView.findViewById(R.id.tv_tel);
            convertView.setTag(viewHolder);

        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tv_name.setText(list.get(position).nickName);
        viewHolder.tv_tel.setText(list.get(position).phoneNum);
       //判断level所属的人员权限是?
        switch (list.get(position).level) {

            case Constant.POWER_TEACHER:
                viewHolder.tv_tel.setText(list.get(position).phoneNum + "(老师)");
                break;
            case Constant.POWER_ADMIN:
                viewHolder.tv_tel.setText(list.get(position).phoneNum + "(管理员)");
                break;
            case Constant.POWER_PARENT:
                viewHolder.tv_tel.setText(list.get(position).phoneNum + "(亲人)");
                break;
            case Constant.POWER_FRIEND:
                viewHolder.tv_tel.setText(list.get(position).phoneNum + "(朋友)");
                break;

        }

        return convertView;
    }
    private class ViewHolder {

        private TextView tv_name;
        private TextView tv_tel;

    }
}
